<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="供应商交易历史" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link href="/css/Query.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="/css/BillList.css" />
<script src="/js/QueryList.js"></script>
<script src="/js/popup_ext.js"></script>
<script language="javascript">
	function doSelect(index){
		var ob_arr = document.getElementsByName("query_checkbox");
		var arr=new Array();
		if (ob_arr.length>=index){
			var obj=ob_arr[index-1];
			arr[0]=new Array(obj.getAttribute("p_id"),obj.getAttribute("p_nam"),obj.getAttribute("p_cod"),obj.getAttribute("p_uni"),obj.getAttribute("i_amo"),obj.getAttribute("i_pri"),obj.getAttribute("i_cos"));
			parent.popRetVal=arr;
		}
		parent.ClosePop();
	}
	function doGo(pageIndex){
		var str=getSearchCondition();
		window.location="/purchase/PurchaseBillItemListForSelect.ihtm?"+str+"&current_page="+pageIndex;
	}
	function doJump(pageIndex){
		if(window.event.keyCode==13){
			doGo(pageIndex);
		}
	}
	function DoubleClick(it){
		var ob_arr = document.getElementsByName("query_checkbox");
		var arr=new Array();
		if(ob_arr.length>=it.getAttribute("index")){
			var obj=ob_arr[it.getAttribute("index")-1];
			arr[0]=new Array(obj.getAttribute("p_id"),obj.getAttribute("p_nam"),obj.getAttribute("p_cod"),obj.getAttribute("p_uni"),obj.getAttribute("i_amo"),obj.getAttribute("i_pri"),obj.getAttribute("i_cos"));
			parent.popRetVal=arr;
		}
		parent.ClosePop();
	}
	function doMutiSelect(){
		var ob_arr = document.getElementsByName("query_checkbox");
		var arr=new Array();
		for (i=0;i<ob_arr.length;i++){
			if ((ob_arr[i].checked == true)){
				arr.push(new Array(ob_arr[i].getAttribute("p_id"),ob_arr[i].getAttribute("p_nam"),ob_arr[i].getAttribute("p_cod"),ob_arr[i].getAttribute("p_uni"),ob_arr[i].getAttribute("i_amo"),ob_arr[i].getAttribute("i_pri"),ob_arr[i].getAttribute("i_cos")));
			}
		}
		if(arr.length>0){
			parent.popRetVal=arr;
			parent.ClosePop();
		}else{
			ShowAlert('提示框','请选择交易历史！',200,100);
			return;
		}
	}
	function doCancel(){
		parent.ClosePop();
	}
	function doInit(){
		//Window_Onload();
	}
	function checkInput(){
		if(window.event.keyCode==13){
			doSearch();
		}
	}
	function createPageParaStr(){
		var str="pro_name="+encodeURIComponent(document.getElementById("pro_name").value);
		str=str+"&pro_code="+encodeURIComponent(document.getElementById("pro_code").value);
		str=str+"&pt_id="+document.getElementById("pt_id").value;
		
		return str;
	}

	function createProgramParaStr(){
		var str="pro_name="+encodeURIComponent(document.getElementById("hid_pro_name").value);
		str=str+"&pro_code="+encodeURIComponent(document.getElementById("hid_pro_code").value);
		str=str+"&pt_id=${ptId}";
		
		return str;
	}
	function doSearch(){
		var str="id=${providerId}&bill_type=${billType}&ts_id=${tsId}";
		if(IsAdvSearch){//高级
			str=str+"&search_type=1";
			if(document.getElementById("cb_pro_name").checked){
				var proName=document.getElementById("pro_name").value.trim();
				if(proName==null || proName==""){
					ShowAlert('提示框','请输入品名规格',200,100);
					return;
				}
				str=str+"&cb_pro_name=1";
			}
			if(document.getElementById("cb_pro_code").checked){
				var proCode=document.getElementById("pro_code").value.trim();
				if(proCode==null || proCode==""){
					ShowAlert('提示框','请输入材料编号',200,100);
					return;
				}
				str=str+"&cb_pro_code=1";
			}
			if(document.getElementById("cb_pt").checked){
				var ptId=document.getElementById("pt_id").value;
				if(ptId==null || ptId=="" || ptId=="0"){
					ShowAlert('提示框','请选择材料类别',200,100);
					return;
				}
				str=str+"&cb_pt=1";
			}
		}else{//快速
			str=str+"&search_type=2";
		}
		var paraStr=createPageParaStr();
		if(paraStr!=""){
			str=str+"&"+paraStr;
		}
		window.location="/purchase/PurchaseBillItemListForSelect.ihtm?"+str;
	}
	function getSearchCondition(){
		var searchType="${searchType}";
		var str="id=${providerId}&bill_type=${billType}&ts_id=${tsId}&search_type="+searchType;
		if(searchType=="1"){//高级
			<c:if test="${cbProName=='1'}">str=str+"&cb_pro_name=1";</c:if>
			<c:if test="${cbProCode=='1'}">str=str+"&cb_pro_code=1";</c:if>
			<c:if test="${cbPt=='1'}">str=str+"&cb_pt=1";</c:if>
		}else{//快速
			
		}
		var paraStr=createProgramParaStr();
		if(paraStr!=""){
			str=str+"&"+paraStr;
		}
		return str;
	}
	function doAutoCheck(objId){
		if(document.getElementById(objId).style.visibility!="hidden"){
			document.getElementById(objId).checked=true;
		}
	}
	function doInit(){
		document.getElementById("pro_name").focus();
	}
</script>
</head>
<body oncontextmenu="return false" onload="doInit();">
<div class="Wrap"><!-- 页面主框架 -->
    
	<div id="ListContainer" class="Container"><!-- 主体容器 -->
	    
	    <!-- 标题栏 -->
	    <div class="Heading BillIcon">
	        <div class="HeadingContent">
	            <h1>供应商交易历史</h1>
	            <span class="Note">可以选择之前交易的材料价格，直接作为采购单的价格</span>
	        </div>
	    </div>
	
		<!-- 主内容 -->
		<div class="Content">
	        <!-- 筛选控件栏 -->
	        <div class="FilterBar ClearFix">
	            <div class="SearchIcon"></div>
	            <span class="fl">
	            	<table class="MoreOption" cellpadding="0" cellspacing="0">
	            		<th class="c1" width="80px">
	            			<input type="checkbox" name="cb_pro_name" id="cb_pro_name" <c:if test="${cbProName=='1' || searchType=='2'}">checked="true"</c:if> style="visibility:hidden;" />
	            			品名规格
	            		</th>
	            		<td class="c1" width="260px">
	            			<input type="text" class="TextBox" name="pro_name" id="pro_name" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_pro_name');" value="<c:out value="${proName}" />" >
							<input type="hidden" id="hid_pro_name" value="<c:out value="${proName}" />">
	            		</td>
	            	</table>
	            </span>
	            <span class="fr">
	            	<a href="javascript:;" id="lnkMoreOption">更多查询选项</a>
		  			<input type="button" value=" 查 询" onClick="doSearch();" class="buttom search-but" id="sSearchButton" name="sSearchButton">
		  			<input type="button" value=" 选 择" onClick="doMutiSelect();" id="sSelectButton" name="sSelectButton" class="buttom search-select">
	            </span>
				<div id="dvMoreOptionBox" class="MoreOptionBox" style="display:none;">
					<table class="MoreOption" cellpadding="0" cellspacing="0">
						<tr>
							<th class="c1" width="80px">
			        			<input name="" type="checkbox" name="cb_pro_code" id="cb_pro_code" <c:if test="${cbProCode=='1'}">checked="true"</c:if> />
			        			材料编号
			        		</th>
			        		<td class="c1" width="260px">
			        			<input type="text" class="TextBox" id="pro_code" name="pro_code" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_pro_code');" value="<c:out value="${proCode}" />">
								<input type="hidden" id="hid_pro_code" value="<c:out value="${proCode}" />">
			    			</td>
			    		</tr>
			    		<tr>
			    			<th class="c1">
	                        	<input type="checkbox" name="cb_pt" id="cb_pt" <c:if test="${cbPt=='1'}">checked="true"</c:if>>
	                        	材料类别
	                        </th>
	                    	<td class="c1">
	                        	<select name="pt_id" id="pt_id" onFocus="doAutoCheck('cb_pt');">
						  			<option value="0">==请选择==</option>
						  			<commonTag:createSelectTree list="${ptList}" emptyOption="0" defaultValue="${ptId}" />
					  			</select>
	                    	</td>
			    		</tr>
			    	</table>
			    	
			    	<div class="OptionOrderBy">
	                    <span class="fr"><a href="javascript:;" id="lnkHiddenOption">隐藏查询选项</a></span>
	                </div>
				</div>
			</div>
			
			<!-- 提示信息显示栏 -->
	        <div class="MsgBar">
	            <%@include file="../inc/AlertMsg.jsp"%>
	        </div>

		    <div class="table-list">
		        <table width="100%">
					<tr>
						<th width="14"><input type="checkbox" onClick="javascript:checkall(this);"></th>
						<th width="14%">日期</th>
						<th width="14%">材料编号</th>
						<th width="20%">品名规格</th>
						<th width="10%">单位</th>
						<th width="10%">数量</th>
						<th width="10%">单价</th>
						<th width="14%">金额</th>
						<th width="8%" >操作</th>
					</tr>
					<c:forEach var="item" items="${qr.list}" varStatus="i">
					<c:if test="${(i.index mod 2)==0}"><c:set var="trClass" value="query_list_data_tr1" /></c:if>
					<c:if test="${(i.index mod 2)!=0}"><c:set var="trClass" value="query_list_data_tr2" /></c:if>
					<tr class="${trClass}" index="${i.index+1}" style='cursor:pointer;' ondblclick='javascript:DoubleClick(this)' onClick='javascript:ClickCheck(this,true)' onmouseout='javascript:mouseout(this)' onmouseover='javascript:mouseover(this)'>
						<td><input type="checkbox" onClick="javascript:ClickCheck(this,true);" name='query_checkbox' p_id="${item[8]}" p_nam="<c:out value="${item[2]}" />" p_cod="<c:out value="${item[3]}" />" p_uni='${item[4]}' i_amo='<commonTag:parseBigDecimal source="${item[5]}" />' i_pri='<commonTag:parseBigDecimal source="${item[6]}" />' i_cos="<commonTag:parseBigDecimal source="${item[7]}" />"></td>
						<td><fmt:formatDate value="${item[1]}" pattern="yyyy-MM-dd"/></td>
						<td>${item[2]}</td>
						<td>${item[3]}</td>
						<td>${item[4]}</td>
						<td>${item[5]}</td>
						<td>${item[6]}</td>
						<td>${item[7]}</td>
						<td>
							<a href="javascript:doSelect('${i.index+1}');">选择</a>
						</td>
					</tr>
					</c:forEach>
				</table>
				<c:set var="showPagesSelectButton" value="Y" />
				<c:set var="pagesSelectButtonFun" value="doMutiSelect()" />
			</div>
      		<!-- 底栏 分页、操作等 -->
	        <div class="BottomToolBar ClearFix">
			    <%@include file="../inc/Pages.jsp"%>
	        </div>
			
		</div>
	</div>
</div>
</body>
</html>
<script type="text/javascript">
	function ChangeWindowSize( container, maxWidth ){
	    setTimeout( function(){
	        var w1 = document.documentElement.clientWidth-40;
	        if( w1>maxWidth ) w1 = maxWidth;
	        else if( w1<870 ) w1 = 860;
	        container.style.width = w1+'px';
	    }, 300 );
	}
	var IsAdvSearch = false;
	(function(){
	    var ListContainer = document.getElementById('ListContainer');
	    ChangeWindowSize( ListContainer, 2020 );    // 超过 1280 的最大 1260 ，不全部铺满
	
	    var lnkMoreOption   = document.getElementById('lnkMoreOption');
	    var lnkHiddenOption = document.getElementById('lnkHiddenOption');
	    lnkMoreOption.onclick = function(){
	    	IsAdvSearch = true;
	        document.getElementById('dvMoreOptionBox').style.display = 'block';
	        document.getElementById('cb_pro_name').style.visibility = 'visible';
	        this.style.visibility = 'hidden';
	    };
	    lnkHiddenOption.onclick = function(){
	    	IsAdvSearch = false;
	        document.getElementById('dvMoreOptionBox').style.display = 'none';
	        document.getElementById('cb_pro_name').style.visibility = 'hidden';
	        lnkMoreOption.style.visibility = 'visible';
	    };
	})();
</script>
